﻿using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;

namespace Framework
{
    /// <summary>
    /// 基于HttpListener的Feature
    /// HttpContext与HttpListener的适配层的具体实现
    /// </summary>
    public class HttpListenerFeature : IHttpRequestFeature, IHttpResponseFeature
    {
        private readonly HttpListenerContext _context;

        public HttpListenerFeature(HttpListenerContext context)
        {
            _context = context;
        }

        Uri IHttpRequestFeature.Url
        {
            get { return _context.Request.Url; }
        }

        NameValueCollection IHttpRequestFeature.Headers
        {
            get { return _context.Request.Headers; }
        }

        NameValueCollection IHttpResponseFeature.Headers
        {
            get { return _context.Response.Headers; }
        }

        Stream IHttpRequestFeature.Body
        {
            get { return _context.Request.InputStream; }
        }

        Stream IHttpResponseFeature.Body
        {
            get { return _context.Response.OutputStream; }
        }

        int IHttpResponseFeature.StatusCode
        {
            get { return _context.Response.StatusCode; }
            set { _context.Response.StatusCode = value; }
        }
    }
}
